package com.sloera.jvm.oom;

import java.util.ArrayList;
import java.util.List;

/**
 * @author sloera
 * @create 2020/5/3
 * -Xms10m -Xmx10m -XX:+PrintGCDetails -XX:MaxDirectMemorySize=5m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$ModuleFileDir$\ -XX:ErrorFile=./hs_err_pid<pid>.log
 * java.lang.OutOfMemoryError: GC overhead limit exceeded
 */
public class GCOverheadDemo {
    public static void main(String[] args) throws InterruptedException {
        int i = 0;
        //TimeUnit.SECONDS.sleep(5);
        List<String> list = new ArrayList<>();
        try {
            while (true) {
                list.add(String.valueOf(++i).intern());
            }
        } catch (Throwable e) {
            System.out.println("i:" + i);
            e.printStackTrace();
            throw e;
        }
    }
}
